/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.oea.hibernate.entities;

import com.oea.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author unnati
 */
@Table(name="divisions")
@Entity
public class Division extends AbstractEntity
{
    @GeneratedValue
    
    @Column(name = "id")
    @Id
    protected Long id;
    
     
    @Column(name = "semester")
    protected int semester;
    
     
    @Column(name = "name")
    protected String name;
    
    
    @Column(name="bid")
    protected  Long bid;
    
    @Column(name = "addedby")
    protected Long addedby;

    @Transient
    protected  Admin admin;

    @Transient
    protected  Branch branch;
    
    
    public Branch getBranch() {
        return branch;
    }

    public void setBranch() {
        this.branch = (Branch) new Branch().getById(bid);
    }
    
    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin() {
        this.admin = (Admin) new Admin().getById(addedby);
    }
    
    
    public Long getBid() {
        return bid;
    }

    public void setBid(Long bid) {
        this.bid = bid;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
 
    }

    
    
    
    public  List<Division> getDivisions(Long branch_id,Long semester)
    {
        List<Division> li= null;
        
        try 
        {
            Session s=HibernateUtil.getSessionFactory().openSession();
            
            Query q=s.createQuery("from Division where bid="+branch_id+" AND semester="+semester+"");
            li=q.list();
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return li;
    }

    
}
